#ifndef PIN_MAP_H
#define PIN_MAP_H

#define BOARD_TYPE_D4
// #define BOARD_TYPE_C3


#if defined(BOARD_TYPE_D4)
#define HAVE_OLED
// #define HAVE_INA226
#define DIR_1   4
#define PUL_1   2
#define DIR_2   19
#define PUL_2   23
#define TX_1    10
#define RX_1    9
#define TX_2    13
#define RX_2    15
#define LED_PIN     22
#define LIM_SENSOR_PIN_1 14
#define LIM_SENSOR_PIN_1_TRIG_LEVEL LOW
#define LIM_SENSOR_PIN_2 25
#define LIM_SENSOR_PIN_2_TRIG_LEVEL LOW
#define LIM_SENSOR_PIN_3 -1
#define LIM_SENSOR_PIN_3_TRIG_LEVEL LOW
#define LIM_SENSOR_PIN_4 -1
#define LIM_SENSOR_PIN_4_TRIG_LEVEL LOW
#define I2C_SDA 27
#define I2C_SCL 26
#define INA_ADDR1 0x44
#define INA_ADDR2 0x45
#define BOARD_TYPE 0

#elif defined(BOARD_TYPE_C3)
#define HAVE_OLED
#define DIR_1   4
#define PUL_1   5
#define DIR_2   6
#define PUL_2   7
#define TX_1    21
#define RX_1    20
#define TX_2    2
#define RX_2    3
#define LED_PIN     1
#define LIM_SENSOR_PIN_1 9
#define LIM_SENSOR_PIN_1_TRIG_LEVEL LOW
#define LIM_SENSOR_PIN_2 11
#define LIM_SENSOR_PIN_2_TRIG_LEVEL LOW
#define LIM_SENSOR_PIN_3 19
#define LIM_SENSOR_PIN_3_TRIG_LEVEL LOW
#define LIM_SENSOR_PIN_4 18
#define LIM_SENSOR_PIN_4_TRIG_LEVEL LOW
#define I2C_SDA 5
#define I2C_SCL 4
#define BOARD_TYPE 1

#else
#error "BOARD_TYPE not selected"
#define BOARD_TYPE -1
#endif

// --------setting-----
#define SET_IP 0
#define SET_SSID 1
#define SET_PASSWORD 2
#define BROADCAST 3
#define SENDMSG 4
// --------getting-------
#define LOG_WIFI 5

void log_board_msg(Print * serial=&Serial){
    char Board_Type[20];
    // serial->print("Board Type:\n");
    if (BOARD_TYPE == 0){
        strcpy(Board_Type, "PICO-D4");
        // serial->print("\tPICO-D4 Version\n");
    }else if(BOARD_TYPE == 1){
        strcpy(Board_Type, "C3");
        // serial->print("\tC3 Version\n");
    }
    // serial->printf("HardWare Definition:\nTX_1 :\t%d, \tRX_1 :\t%d", TX_1, RX_1);
    // serial->printf("\nTX_2 :\t%d, \tRX_2 :\t%d", TX_2, RX_2);
    // serial->printf("\nPUL_1 :\t%d, \tDIR_1 :\t%d", PUL_1, DIR_1);
    // serial->printf("\nPUL_2 :\t%d, \tDIR_2 :\t%d", PUL_2, DIR_2);
    // serial->printf("\nI2C_SDA :\t%d, \tI2C_SCL :\t%d\n", I2C_SDA, I2C_SCL);
    serial->printf("Board Type: %s\nHardWare Definition:\n\tTX_1 :\t%d, \tRX_1 :\t%d\n\tTX_2 :\t%d, \tRX_2 :\t%d\n\tPUL_1 :\t%d, \tDIR_1 :\t%d\n\tPUL_2 :\t%d, \tDIR_2 :\t%d\n\tSDA :\t%d, \tSCL :\t%d\n",
    Board_Type, TX_1, RX_1, TX_2, RX_2, PUL_1, DIR_1, PUL_2, DIR_2, I2C_SDA, I2C_SCL);
}


void size64Writer(Print *serial, int64_t msg64){
    // 将64位数据通过串口发送出去
    // uint8_t buffer = 0;
    uint8_t buffer[8] ;
    for(uint8_t i=0; i<8; i++){
        buffer[i] = msg64 >> i * 8;
    }
    serial->write(buffer, 8);
}

#endif